#pragma once

#include "Includes.h"


class BipBuffer {
public:
	BipBuffer();

	// returns a pointer to a sequential memory location.
	// returns <amount> : The size of the buffer in bytes.
	char* reserve(int& amount);

	// marks <amount> of bytes in the current buffer as occupied.
	// call this after writing to the buffer returned by reserve().
	// The buffer and size returned by reserve are invalidated by this call
	// and need to be retrieved again before the next write operation
	void commit(int amount);

	// read <amount> of bytes from the beginning of the buffer (FIFO).
	// This releases the space.
	std::string decommit(int amount);

	// returns the amount of sequential memory currently available
	int getBufferCapacity();

	// returns the number of bytes available. This is the maximum
	// amount readable via decommit()
	int getCommittedSize();
	
	// returns the offset of the first occurence of the given character 
	// from the beginning of the buffer. Use this to determine how many
	// characters to read via decommit()
	int find(char c);

	//DEBUG
	void print();

private:
	static const int BUFSIZE = 2048;

	char pos0[BUFSIZE];

	int ixA, szA, szB, ixR, szR;

	//int ixB = 0;

};